﻿"use strict";

(function($$, $, undefined) {

	var old$$ = window[$$];

	var mango = {

		config : {
			version : '0.1',

			fxSpeed : 300,

			lock : {
				timeout : 60 * isperp.lockscreenTimeout,
				idle : 15,
				lockWhenInactive : false
			},

			// - Settings Dialog
			settings : {
				width : 450
			// px: The width of the dialog
			},

			scollToTop : false,
			preloadImages : false

		},

		utils : {
			noBubbling : function(e) {
				e.stopPropagation()
			},

			tryF : function(cb) {
				return function() {
					cb();
				}
			},

			// ! Run functions when the page including all it's ressources is
			// loaded.
			// - This is a shortcut for $(window).load(...)
			ready : function(cb) {
				$(window).load(mango.utils.tryF(cb));
			},

			loaded : function(cb) {

				var _cb = this.loaded.cb;

				!_cb && (_cb = []);

				$.isFunction(cb) ? _cb.push(mango.utils.tryF(cb)) : _cb.forEach(function(f) {
					f()
				});

				this.loaded.cb = _cb;

			},

			preload : function(images) {
				_.defer(function() {
					images.forEach(function(img) {
						(new Image()).src = img;
					});
				});
			}

		},

		isOldIE : !$.support.leadingWhitespace,

		noConflict : function() {
			window[$$] = old$$;
			return this;
		}

	}; // End of 'mango'

	// - Publish functions
	mango.loaded = mango.utils.loaded;
	mango.ready = mango.utils.ready;

	// ! Make $$ public
	window[$$] = {};
	$.extend(window[$$], mango);

})('$$', jQuery); // To change the public name, change $$ in this line.
